/*
 * This file is part of the Gwt-Generator project and was written by Henri Darmet for Objet Direct
 * <http://wwww.objetdirect.com>
 * 
 * Copyright © 2009 Objet Direct
 * 
 * Gwt-Generator is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later version.
 * 
 * Gwt-Generator is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License along with Gwt-Generator. If not, see <http://www.gnu.org/licenses/>.
 */

package com.objetdirect.seam;

import junit.framework.TestCase;

import com.objetdirect.engine.ScriptDescriptor;
import com.objetdirect.engine.TestUtil;
import com.objetdirect.entities.EntityDescriptor;
import com.objetdirect.seam.lists.SelectManyDetailDescriptor;
import com.objetdirect.seam.lists.TransientSelectManyListDescriptor;

public class TestTransientSelectManyList extends TestCase {
	public void testSimpleList() {	
		Seam.clear();
		EntityDescriptor agency = new EntityDescriptor("com.objetdirect.domain", "Agency").
			addStringField("name", null).
			addStringField("phone", null);
		PageDescriptor page = 
			new PageDescriptor("com.objetdirect.actions", "EditAgencies", "views", "edit-agencies");
		TransientSelectManyListDescriptor feature = new TransientSelectManyListDescriptor(agency).
			showField("name", "Name", 20).
			showField("phone", "Phone", 10);
		page.setFeature(feature);
		page.build();		
		TestUtil.assertText(page.getJavaText(),
			"package com.objetdirect.actions;",
			"",
			"import com.objetdirect.domain.Agency;",
			"import java.util.HashMap;",
			"import java.util.List;",
			"import javax.persistence.EntityManager;",
			"import org.jboss.seam.annotations.In;",
			"import org.jboss.seam.annotations.Name;",
			"import org.jboss.seam.annotations.Scope;",
			"import org.jboss.seam.core.Conversation;",
			"import org.jboss.seam.ScopeType;",
			"",
			"@Name(\"editAgencies\")",
			"@Scope(ScopeType.CONVERSATION)",
			"public class EditAgenciesAnimator {",
			"",
			"	@In",
			"	EntityManager entityManager;",
			"	List<Agency> agencies = null;",
			"",
			"	public EditAgenciesAnimator() {",
			"		if (Conversation.instance().isLongRunning()) {",
			"			Conversation.instance().end(true);",
			"			Conversation.instance().leave();",
			"		}",
			"		Conversation.instance().begin();",
			"	}",
			"",
			"	@SuppressWarnings(\"unchecked\")",
			"	public List<Agency> getAgencies() {",
			"		if (agencies==null) {",
			"			agencies = entityManager.createQuery(\"from Agency\").getResultList();",
			"		}",
			"		return agencies;",
			"	}",
			"",
			"}"
		);
		TestUtil.assertText(page.getFaceletText(),
			"<!DOCTYPE composition PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"",
			"			\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">",
			"<ui:composition xmlns=\"http://www.w3.org/1999/xhtml\"",
			"	xmlns:s=\"http://jboss.com/products/seam/taglib\"",
			"	xmlns:ui=\"http://java.sun.com/jsf/facelets\"",
			"	xmlns:f=\"http://java.sun.com/jsf/core\"",
			"	xmlns:h=\"http://java.sun.com/jsf/html\"",
			"	xmlns:ice=\"http://www.icesoft.com/icefaces/component\"",
			"	template=\"/layout/template.xhtml\">",
			"",
			"<ui:define name=\"body\">",
			"",
			"	<h:messages styleClass=\"message\"/>",
			"",
			"	<ice:form id=\"pageForm\">",
			"		<ice:panelGroup	styleClass=\"formBorderHighlight\">",
			"",
			"			<div class=\"dialog\">",
			"				<h:panelGroup>",
			"					<ice:dataTable id=\"agencies\" value=\"#{editAgencies.agencies}\" var=\"agency\"",
			"						rows=\"10\" resizable=\"true\" columnWidths=\"200px,100px\">",
			"						<ice:column>",
			"							<f:facet name=\"header\">Name</f:facet>",
			"							<h:outputText value=\"#{agency.name}\" />",
			"						</ice:column>",
			"						<ice:column>",
			"							<f:facet name=\"header\">Phone</f:facet>",
			"							<h:outputText value=\"#{agency.phone}\" />",
			"						</ice:column>",
			"					</ice:dataTable>",
			"					<ice:dataPaginator for=\"agencies\" fastStep=\"10\" paginator=\"true\" paginatorMaxPages=\"9\">",
			"						<f:facet name=\"first\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-first.gif\" style=\"border:none;\"/>",
			"						</f:facet>",
			"						<f:facet name=\"last\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-last.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"						<f:facet name=\"previous\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-previous.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"						<f:facet name=\"next\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-next.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"						<f:facet name=\"fastforward\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-ff.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"						<f:facet name=\"fastrewind\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-fr.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"					</ice:dataPaginator>",
			"				</h:panelGroup>",
			"			</div>",
			"		</ice:panelGroup>",
			"	</ice:form>",
			"</ui:define>",
			"</ui:composition>"
		);
	}

	public void testSimpleListWithDelete() {	
		Seam.clear();
		EntityDescriptor agency = new EntityDescriptor("com.objetdirect.domain", "Agency").
			addStringField("name", null).
			addStringField("phone", null);
		PageDescriptor page = 
			new PageDescriptor("com.objetdirect.actions", "EditAgencies", "views", "edit-agencies");
		TransientSelectManyListDescriptor feature = new TransientSelectManyListDescriptor(agency).
			showField("name", "Name", 20).
			showField("phone", "Phone", 10).
			addDelete("Voulez-vous supprimer l'agence : #{agencyToDelete.name} ?");
		page.setFeature(feature);
		page.build();
		
		TestUtil.assertText(page.getJavaText(),
			"package com.objetdirect.actions;",
			"",
			"import com.objetdirect.domain.Agency;",
			"import java.util.HashMap;",
			"import java.util.List;",
			"import javax.persistence.EntityManager;",
			"import org.jboss.seam.annotations.In;",
			"import org.jboss.seam.annotations.Name;",
			"import org.jboss.seam.annotations.Scope;",
			"import org.jboss.seam.core.Conversation;",
			"import org.jboss.seam.ScopeType;",
			"",
			"@Name(\"editAgencies\")",
			"@Scope(ScopeType.CONVERSATION)",
			"public class EditAgenciesAnimator {",
			"",
			"	@In",
			"	EntityManager entityManager;",
			"	List<Agency> agencies = null;",
			"	Agency targetAgencyForDeletion = null;",
			"	static final int OP_NONE = 0;",
			"	static final int OP_DELETE = 1;",
			"	int operation = OP_NONE;",
			"",
			"	public EditAgenciesAnimator() {",
			"		if (Conversation.instance().isLongRunning()) {",
			"			Conversation.instance().end(true);",
			"			Conversation.instance().leave();",
			"		}",
			"		Conversation.instance().begin();",
			"	}",
			"",
			"	@SuppressWarnings(\"unchecked\")",
			"	public List<Agency> getAgencies() {",
			"		if (agencies==null) {",
			"			agencies = entityManager.createQuery(\"from Agency\").getResultList();",
			"		}",
			"		return agencies;",
			"	}",
			"	",
			"	public void requestAgencyDeletion(Agency agency) {",
			"		targetAgencyForDeletion = agency;",
			"		operation = OP_DELETE;",
			"	}",
			"	",
			"	public Agency getTargetAgencyForDeletion() {",
			"		return targetAgencyForDeletion;",
			"	}",
			"	",
			"	void deleteAgency(Agency agency) {",
			"		agencies.remove(agency);",
			"		entityManager.remove(agency);",
			"	}",
			"	",
			"	public int getOperation() {",
			"		return operation;",
			"	}",
			"	",
			"	public void setOperation(int operation) {",
			"		this.operation = operation;",
			"	}",
			"	",
			"	public void cancelOperation() {",
			"		operation = OP_NONE;",
			"	}",
			"	",
			"	public void continueOperation() {",
			"		if (operation == OP_DELETE) {",
			"			if (targetAgencyForDeletion != null) {",
			"				deleteAgency(targetAgencyForDeletion);",
			"				targetAgencyForDeletion = null;",
			"			}",
			"		}",
			"		operation = OP_NONE;",
			"	}",
			"	",
			"	public boolean isConfirmRequested() {",
			"		return operation != OP_NONE;",
			"	}",
			"	",
			"	public void setConfirmRequested(boolean confirmRequested) {",
			"		if (!confirmRequested) {",
			"			cancelOperation();",
			"		}",
			"	}",
			"",
			"}"
		);
		TestUtil.assertText(page.getFaceletText(),
			"<!DOCTYPE composition PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"",
			"			\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">",
			"<ui:composition xmlns=\"http://www.w3.org/1999/xhtml\"",
			"	xmlns:s=\"http://jboss.com/products/seam/taglib\"",
			"	xmlns:ui=\"http://java.sun.com/jsf/facelets\"",
			"	xmlns:f=\"http://java.sun.com/jsf/core\"",
			"	xmlns:h=\"http://java.sun.com/jsf/html\"",
			"	xmlns:ice=\"http://www.icesoft.com/icefaces/component\"",
			"	template=\"/layout/template.xhtml\">",
			"",
			"<ui:define name=\"body\">",
			"",
			"	<h:messages styleClass=\"message\"/>",
			"",
			"	<ice:form id=\"pageForm\">",
			"		<ice:panelGroup	styleClass=\"formBorderHighlight\">",
			"",
			"			<div class=\"dialog\">",
			"				<h:panelGroup>",
			"					<ice:dataTable id=\"agencies\" value=\"#{editAgencies.agencies}\" var=\"agency\"",
			"						rows=\"10\" resizable=\"true\" columnWidths=\"200px,100px,100px\">",
			"						<ice:column>",
			"							<f:facet name=\"header\">Name</f:facet>",
			"							<h:outputText value=\"#{agency.name}\" />",
			"						</ice:column>",
			"						<ice:column>",
			"							<f:facet name=\"header\">Phone</f:facet>",
			"							<h:outputText value=\"#{agency.phone}\" />",
			"						</ice:column>",
			"						<ice:column>",
			"							<h:commandButton value=\"del\" action=\"#{editAgencies.requestAgencyDeletion(agency)}\"/>",
			"						</ice:column>",
			"					</ice:dataTable>",
			"					<ice:dataPaginator for=\"agencies\" fastStep=\"10\" paginator=\"true\" paginatorMaxPages=\"9\">",
			"						<f:facet name=\"first\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-first.gif\" style=\"border:none;\"/>",
			"						</f:facet>",
			"						<f:facet name=\"last\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-last.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"						<f:facet name=\"previous\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-previous.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"						<f:facet name=\"next\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-next.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"						<f:facet name=\"fastforward\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-ff.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"						<f:facet name=\"fastrewind\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-fr.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"					</ice:dataPaginator>",
			"				</h:panelGroup>",
			"			</div>",
			"		</ice:panelGroup>",
			"		<ice:panelPopup modal=\"true\" draggable=\"true\" styleClass=\"popup\" rendered=\"#{editAgencies.confirmRequested}\">",
			"			<f:facet name=\"header\">",
			"				<ice:panelGrid styleClass=\"title\" cellpadding=\"0\" cellspacing=\"0\" columns=\"2\">",
			"					<ice:outputText value=\"Confirmation\"/>",
			"				</ice:panelGrid>",
			"			</f:facet>",
			"			<f:facet name=\"body\">",
			"				<ice:panelGrid width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" column=\"1\" styleClass=\"body\">",
			"					<ice:outputText value=\"Voulez-vous supprimer l'agence : #{editAgencies.targetAgencyForDeletion.name} ?\" rendered=\"#{editAgencies.operation==1}\"/>",
			"					<div class=\"actionButtons\">",
			"						<h:commandButton value=\"valider\" action=\"#{editAgencies.continueOperation}\"/>",
			"						<h:commandButton value=\"annuler\" immediate=\"true\" action=\"#{editAgencies.cancelOperation}\"/>",
			"					</div>",
			"				</ice:panelGrid>",
			"			</f:facet>",
			"		</ice:panelPopup>",
			"	</ice:form>",
			"</ui:define>",
			"</ui:composition>"
		);
	}

	public void testSimpleDetail() {	
		Seam.clear();
		EntityDescriptor agency = new EntityDescriptor("com.objetdirect.domain", "Agency").
			addStringField("name", null).
			addStringField("phone", null);
		PageDescriptor page = 
			new PageDescriptor("com.objetdirect.actions", "EditAgencies", "views", "edit-agencies");
		TransientSelectManyListDescriptor feature = new TransientSelectManyListDescriptor(agency).
			showField("name", "Name", 20).
			showField("phone", "Phone", 10);
		SelectManyDetailDescriptor detail = new SelectManyDetailDescriptor();
		detail.addForm(new FormDescriptor().
			editStringField("name", "Nom de l'agence", 30).
			editStringField("phone", "Telephone", 10)
		);
		feature.setDetail(detail);
		page.setFeature(feature);
		page.build();
		
		TestUtil.assertText(page.getJavaText(),
			"package com.objetdirect.actions;",
			"",
			"import com.objetdirect.domain.Agency;",
			"import com.objetdirect.jsffrmk.GuiUtil;",
			"import java.util.ArrayList;",
			"import java.util.HashMap;",
			"import java.util.List;",
			"import java.util.Map;",
			"import javax.faces.context.FacesContext;",
			"import javax.persistence.EntityManager;",
			"import org.jboss.seam.annotations.In;",
			"import org.jboss.seam.annotations.Name;",
			"import org.jboss.seam.annotations.Scope;",
			"import org.jboss.seam.core.Conversation;",
			"import org.jboss.seam.ScopeType;",
			"",
			"@Name(\"editAgencies\")",
			"@Scope(ScopeType.CONVERSATION)",
			"public class EditAgenciesAnimator {",
			"",
			"	@In",
			"	EntityManager entityManager;",
			"	List<Agency> agencies = null;",
			"	Map<Agency, Boolean> selectedAgencies = new HashMap<Agency, Boolean>();",
			"	List<Agency> openedAgencies = null;",
			"	int currentOpenedAgenciesIndex = 0;",
			"	Agency currentAgency = null;",
			"	static final int AGENCIES_FAST_STEP = 10;",
			"	static final int AGENCIES_NO_NAVIGATION = 0;",
			"	static final int AGENCIES_GO_FIRST = 1;",
			"	static final int AGENCIES_GO_FAST_PREVIOUS = 2;",
			"	static final int AGENCIES_GO_PREVIOUS = 3;",
			"	static final int AGENCIES_GO_NEXT = 4;",
			"	static final int AGENCIES_GO_FAST_NEXT = 5;",
			"	static final int AGENCIES_GO_LAST = 6;",
			"	static final int CLOSE_AGENCIES_POPUP = 7;",
			"	int agenciesNavigation = AGENCIES_NO_NAVIGATION;",
			"	String currentAgencyName;",
			"	String currentAgencyPhone;",
			"",
			"	public EditAgenciesAnimator() {",
			"		if (Conversation.instance().isLongRunning()) {",
			"			Conversation.instance().end(true);",
			"			Conversation.instance().leave();",
			"		}",
			"		Conversation.instance().begin();",
			"	}",
			"",
			"	@SuppressWarnings(\"unchecked\")",
			"	public List<Agency> getAgencies() {",
			"		if (agencies==null) {",
			"			agencies = entityManager.createQuery(\"from Agency\").getResultList();",
			"			selectedAgencies = new HashMap<Agency, Boolean>();",
			"		}",
			"		return agencies;",
			"	}",
			"	",
			"	public Map<Agency, Boolean> getSelectedAgencies() {",
			"		return selectedAgencies;",
			"	}",
			"	",
			"	public Agency getCurrentAgency() {",
			"		return currentAgency;",
			"	}",
			"	",
			"	void setCurrentAgency(int selectedIndex) {",
			"		if (openedAgencies.size()==0)",
			"			return;",
			"		currentAgency = openedAgencies.get(index);",
			"		currentAgencyName = currentAgency.getName();",
			"		currentAgencyPhone = currentAgency.getPhone();",
			"	}",
			"	",
			"	public boolean isCurrentAgencyVisible() {",
			"		return currentAgency != null;",
			"	}",
			"	",
			"	public void setCurrentAgencyVisible(boolean visible) {",
			"	}",
			"	",
			"	void clearCurrentAgency() {",
			"		openedAgencies = null;",
			"		currentAgency = null;",
			"	}",
			"	",
			"	boolean isCurrentAgencyValid() {",
			"		return !FacesContext.getCurrentInstance().getMessages().hasNext();",
			"	}",
			"	",
			"	public void cancelCurrentAgency() {",
			"		GuiUtil.cancelGui();",
			"		if (openedAgencies.size()==0)",
			"			clearCurrentAgency();",
			"		else",
			"			setCurrentAgency(currentOpenedAgenciesIndex);",
			"	}",
			"	",
			"	public void validateCurrentAgency() {",
			"		if (isCurrentAgencyValid()) {",
			"			currentAgency.setName(currentAgencyName);",
			"			currentAgency.setPhone(currentAgencyPhone);",
			"			return true;",
			"		}",
			"		else",
			"			return false;",
			"	}",
			"	",
			"	boolean isCurrentAgencyDirty() {",
			"		if (currentAgency==null)",
			"			return false;",
			"		if (!GuiUtil.equals(currentAgencyName, currentAgency.getName()))",
			"			return true;",
			"		if (!GuiUtil.equals(currentAgencyPhone, currentAgency.getPhone()))",
			"			return true;",
			"		return false;",
			"	}",
			"	",
			"	public boolean isConfirmAgenciesNavigationRequested() {",
			"		return agenciesNavigation!=AGENCIES_NO_NAVIGATION;",
			"	}",
			"	",
			"	public void cancelAgenciesNavigation() {",
			"		agenciesNavigation = AGENCIES_NO_NAVIGATION;",
			"	}",
			"	",
			"	void doAgenciesGoFirst() {",
			"		currentOpenedAgenciesIndex = 0;",
			"		setCurrentAgency(currentOpenedAgenciesIndex);",
			"	}",
			"	",
			"	public void agenciesGoFirst() {",
			"		if (isCurrentAgencyDirty())",
			"			agenciesNavigation = AGENCIES_GO_FIRST;",
			"		else",
			"			doAgenciesGoFirst();",
			"	}",
			"	",
			"	void doAgenciesGoFastPrevious() {",
			"		currentOpenedAgenciesIndex -= AGENCIES_FAST_STEP;",
			"		if (currentOpenedAgenciesIndex<0)",
			"			currentOpenedAgenciesIndex=0;",
			"		setCurrentAgency(currentOpenedAgenciesIndex);",
			"	}",
			"	",
			"	public void agenciesGoFastPrevious() {",
			"		if (isCurrentAgencyDirty())",
			"			agenciesNavigation = AGENCIES_GO_FAST_PREVIOUS;",
			"		else",
			"			doAgenciesGoFastPrevious();",
			"	}",
			"	",
			"	void doAgenciesGoPrevious() {",
			"		currentOpenedAgenciesIndex -= 1;",
			"		if (currentOpenedAgenciesIndex<0)",
			"			currentOpenedAgenciesIndex=0;",
			"		setCurrentAgency(currentOpenedAgenciesIndex);",
			"	}",
			"	",
			"	public void agenciesGoPrevious() {",
			"		if (isCurrentAgencyDirty())",
			"			agenciesNavigation = AGENCIES_GO_PREVIOUS;",
			"		else",
			"			doAgenciesGoPrevious();",
			"	}",
			"	",
			"	void doAgenciesGoNext() {",
			"		currentOpenedAgenciesIndex += 1;",
			"		if (currentOpenedAgenciesIndex>=openedAgencies.size())",
			"			currentOpenedAgenciesIndex=openedAgencies.size()-1;",
			"		setCurrentAgency(currentOpenedAgenciesIndex);",
			"	}",
			"	",
			"	public void agenciesGoNext() {",
			"		if (isCurrentAgencyDirty())",
			"			agenciesNavigation = AGENCIES_GO_NEXT;",
			"		else",
			"			doAgenciesGoNext();",
			"	}",
			"	",
			"	void doAgenciesGoFastNext() {",
			"		currentOpenedAgenciesIndex += AGENCIES_FAST_STEP;",
			"		if (currentOpenedAgenciesIndex>=openedAgencies.size())",
			"			currentOpenedAgenciesIndex=openedAgencies.size()-1;",
			"		setCurrentAgency(currentOpenedAgenciesIndex);",
			"	}",
			"	",
			"	public void agenciesGoFastNext() {",
			"		if (isCurrentAgencyDirty())",
			"			agenciesNavigation = AGENCIES_GO_FAST_NEXT;",
			"		else",
			"			doAgenciesGoFastNext();",
			"	}",
			"	",
			"	void doAgenciesGoLast() {",
			"		currentOpenedAgenciesIndex = openedAgencies.size()-1;",
			"		setCurrentAgency(currentOpenedAgenciesIndex);",
			"	}",
			"	",
			"	public void agenciesGoLast() {",
			"		if (isCurrentAgencyDirty())",
			"			agenciesNavigation = AGENCIES_GO_LAST;",
			"		else",
			"			doAgenciesGoLast();",
			"	}",
			"	",
			"	public void closeCurrentAgency() {",
			"		if (isCurrentAgencyDirty())",
			"			agenciesNavigation = CLOSE_AGENCIES_POPUP;",
			"		else",
			"			clearCurrentAgency();",
			"	}",
			"	",
			"	void navigateInsideAgencies() {",
			"		if (agenciesNavigation==AGENCIES_GO_FIRST)",
			"			agenciesGoFirst();",
			"		else if (agenciesNavigation==AGENCIES_GO_FAST_PREVIOUS)",
			"			agenciesGoFastPrevious();",
			"		else if (agenciesNavigation==AGENCIES_GO_PREVIOUS)",
			"			agenciesGoPrevious();",
			"		else if (agenciesNavigation==AGENCIES_GO_NEXT)",
			"			agenciesGoNext();",
			"		else if (agenciesNavigation==AGENCIES_GO_FAST_NEXT)",
			"			agenciesGoFastNext();",
			"		else if (agenciesNavigation==AGENCIES_GO_LAST)",
			"			agenciesGoLast();",
			"		else if (agenciesNavigation==CLOSE_AGENCIES_POPUP)",
			"			closeCurrentAgency();",
			"		agenciesNavigation = AGENCIES_NO_NAVIGATION;",
			"	}",
			"	",
			"	public void saveAndNavigateInsideAgencies() {",
			"		validateCurrentAgency();",
			"		navigateInsideAgencies();",
			"	}",
			"	",
			"	public void cancelAndNavigateInsideAgencies() {",
			"		cancelCurrentAgency();",
			"		navigateInsideAgencies();",
			"	}",
			"	",
			"	public String getCurrentAgencyName() {",
			"		return currentAgencyName;",
			"	}",
			"	",
			"	public void setCurrentAgencyName(String currentAgencyName) {",
			"		this.currentAgencyName = currentAgencyName;",
			"	}",
			"	",
			"	public String getCurrentAgencyPhone() {",
			"		return currentAgencyPhone;",
			"	}",
			"	",
			"	public void setCurrentAgencyPhone(String currentAgencyPhone) {",
			"		this.currentAgencyPhone = currentAgencyPhone;",
			"	}",
			"	",
			"	public boolean openSelectedAgencies() {",
			"		openedAgencies = new ArrayList<Agency>();",
			"		for (Agency agency : getAgencies()) {",
			"			if (selectedAgencies.containsKey(agency) && selectedAgencies.get(agency)) {",
			"				openedAgencies.add(agency);",
			"			}",
			"		}",
			"		agenciesGoFirst();",
			"	}",
			"	",
			"	public boolean openAllAgencies() {",
			"		openedAgencies = new ArrayList<Agency>(getAgencies());",
			"		agenciesGoFirst();",
			"	}",
			"",
			"}"
		);
		TestUtil.assertText(page.getFaceletText(),
			"<!DOCTYPE composition PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"",
			"			\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">",
			"<ui:composition xmlns=\"http://www.w3.org/1999/xhtml\"",
			"	xmlns:s=\"http://jboss.com/products/seam/taglib\"",
			"	xmlns:ui=\"http://java.sun.com/jsf/facelets\"",
			"	xmlns:f=\"http://java.sun.com/jsf/core\"",
			"	xmlns:h=\"http://java.sun.com/jsf/html\"",
			"	xmlns:ice=\"http://www.icesoft.com/icefaces/component\"",
			"	template=\"/layout/template.xhtml\">",
			"",
			"<ui:define name=\"body\">",
			"",
			"	<h:messages styleClass=\"message\"/>",
			"",
			"	<ice:form id=\"pageForm\">",
			"		<ice:panelGroup	styleClass=\"formBorderHighlight\">",
			"",
			"			<div class=\"dialog\">",
			"				<h:panelGroup>",
			"					<ice:dataTable id=\"agencies\" value=\"#{editAgencies.agencies}\" var=\"agency\"",
			"						rows=\"10\" resizable=\"true\" columnWidths=\"200px,100px\">",
			"						<ice:column>",
			"							<f:facet name=\"header\">Name</f:facet>",
			"							<ice:rowSelector value=\"#{editAgencies.selectedAgencies[agency]}\" multiple=\"true\" />",
			"							<h:outputText value=\"#{agency.name}\" />",
			"						</ice:column>",
			"						<ice:column>",
			"							<f:facet name=\"header\">Phone</f:facet>",
			"							<h:outputText value=\"#{agency.phone}\" />",
			"						</ice:column>",
			"					</ice:dataTable>",
			"					<ice:dataPaginator for=\"agencies\" fastStep=\"10\" paginator=\"true\" paginatorMaxPages=\"9\">",
			"						<f:facet name=\"first\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-first.gif\" style=\"border:none;\"/>",
			"						</f:facet>",
			"						<f:facet name=\"last\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-last.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"						<f:facet name=\"previous\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-previous.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"						<f:facet name=\"next\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-next.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"						<f:facet name=\"fastforward\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-ff.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"						<f:facet name=\"fastrewind\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-fr.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"					</ice:dataPaginator>",
			"					<h:panelGroup>",
			"						<h:commandButton value=\"ouvrir\" action=\"#{editAgencies.openSelectedAgencies}\" rendered=\"#{!editAgencies.currentAgencyVisible}\"/>",
			"						<h:commandButton value=\"ouvrir tout\" action=\"#{editAgencies.openAllAgencies}\" rendered=\"#{!editAgencies.currentAgencyVisible}\"/>",
			"					</h:panelGroup>",
			"				</h:panelGroup>",
			"				<h:panelGroup rendered=\"#{editAgencies.currentAgencyVisible}\">",
			"					<div class=\"mask\"/>",
			"					<h:panelGroup style=\"position:relative\">",
			"						<s:validateAll>",
			"							<h:panelGrid columns=\"4\" rowClasses=\"prop\" columnClasses=\"name,value,name,value\">",
			"								<h:outputText value=\"Nom de l'agence : \" />",
			"								<s:decorate template=\"/layout/edit.xhtml\">",
			"									<h:inputText value=\"#{editAgencies.currentAgencyName}\" size=\"30\"/>",
			"								</s:decorate>",
			"								<h:outputText value=\"Telephone : \" />",
			"								<s:decorate template=\"/layout/edit.xhtml\">",
			"									<h:inputText value=\"#{editAgencies.currentAgencyPhone}\" size=\"10\"/>",
			"								</s:decorate>",
			"							</h:panelGrid>",
			"						</s:validateAll>",
			"						<div class=\"actionButtons\">",
			"							<h:commandButton image=\"/xmlhttp/css/xp/css-images/arrow-first.gif\" action=\"#{editAgencies.agenciesGoFirst}\"/>",
			"							<h:commandButton image=\"/xmlhttp/css/xp/css-images/arrow-fr.gif\" action=\"#{editAgencies.agenciesGoFastPrevious}\"/>",
			"							<h:commandButton image=\"/xmlhttp/css/xp/css-images/arrow-previous.gif\" action=\"#{editAgencies.agenciesGoPrevious}\"/>",
			"							<h:commandButton value=\"valider\" action=\"#{editAgencies.validateCurrentAgency}\" />",
			"							<h:commandButton value=\"fermer\" action=\"#{editAgencies.closeCurrentAgency}\"/>",
			"							<h:commandButton value=\"annuler\" immediate=\"true\" action=\"#{editAgencies.cancelAndNavigateInsideAgencies}\"/>",
			"							<h:commandButton image=\"/xmlhttp/css/xp/css-images/arrow-next.gif\" action=\"#{editAgencies.agenciesGoNext}\"/>",
			"							<h:commandButton image=\"/xmlhttp/css/xp/css-images/arrow-ff.gif\" action=\"#{editAgencies.agenciesGoFastNext}\"/>",
			"							<h:commandButton image=\"/xmlhttp/css/xp/css-images/arrow-last.gif\" action=\"#{editAgencies.agenciesGoLast}\"/>",
			"						</div>",
			"					</h:panelGroup>",
			"				</h:panelGroup>",
			"			</div>",
			"		</ice:panelGroup>",
			"		<ice:panelPopup modal=\"true\" draggable=\"true\" styleClass=\"popup\" rendered=\"#{editAgencies.confirmAgenciesNavigationRequested}\">",
			"			<f:facet name=\"header\">",
			"				<ice:panelGrid styleClass=\"title\" cellpadding=\"0\" cellspacing=\"0\" columns=\"2\">",
			"					<ice:outputText value=\"Confirmation\"/>",
			"				</ice:panelGrid>",
			"			</f:facet> ",
			"			<f:facet name=\"body\">",
			"				<ice:panelGrid width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" column=\"1\" styleClass=\"body\">",
			"					<ice:outputText value=\"Des donnees ont ete modifiees. Voulez vous continuer ?\" />",
			"					<div class=\"actionButtons\">",
			"						<h:commandButton value=\"continuer\" action=\"#{editAgencies.cancelAndNavigateInsideAgencies}\"/>",
			"						<h:commandButton value=\"sauver\" action=\"#{editAgencies.saveAndNavigateInsideAgencies}\"/>",
			"						<h:commandButton value=\"annuler\" immediate=\"true\" action=\"#{editAgencies.cancelAgenciesNavigation}\"/>",
			"					</div>",
			"				</ice:panelGrid>",
			"			</f:facet>",
			"		</ice:panelPopup>",
			"	</ice:form>",
			"</ui:define>",
			"</ui:composition>"
		);
	}

	public void testSimpleDetailWithCreateAndDelete() {	
		Seam.clear();
		EntityDescriptor agency = new EntityDescriptor("com.objetdirect.domain", "Agency").
			addStringField("name", null).
			addStringField("phone", null);
		PageDescriptor page = 
			new PageDescriptor("com.objetdirect.actions", "EditAgencies", "views", "edit-agencies");
		TransientSelectManyListDescriptor feature = new TransientSelectManyListDescriptor(agency).
			showField("name", "Name", 20).
			showField("phone", "Phone", 10).
			addDelete("Voulez-vous supprimer l'agence : #{agencyToDelete.name} ?");
		SelectManyDetailDescriptor detail = new SelectManyDetailDescriptor().
			addCreate(
				new ScriptDescriptor(
					"return new Agency(\"Nom de l'agence\");"
				).replace("Agency", agency.getClassDescriptor())
			);
		detail.addForm(new FormDescriptor().
			editStringField("name", "Nom de l'agence", 30).
			editStringField("phone", "Telephone", 10)
		);
		feature.setDetail(detail);
		page.setFeature(feature);
		page.build();
		
		TestUtil.assertText(page.getJavaText(),
			"package com.objetdirect.actions;",
			"",
			"import com.objetdirect.domain.Agency;",
			"import com.objetdirect.jsffrmk.GuiUtil;",
			"import java.util.ArrayList;",
			"import java.util.HashMap;",
			"import java.util.List;",
			"import java.util.Map;",
			"import javax.faces.context.FacesContext;",
			"import javax.persistence.EntityManager;",
			"import org.jboss.seam.annotations.In;",
			"import org.jboss.seam.annotations.Name;",
			"import org.jboss.seam.annotations.Scope;",
			"import org.jboss.seam.core.Conversation;",
			"import org.jboss.seam.ScopeType;",
			"",
			"@Name(\"editAgencies\")",
			"@Scope(ScopeType.CONVERSATION)",
			"public class EditAgenciesAnimator {",
			"",
			"	@In",
			"	EntityManager entityManager;",
			"	List<Agency> agencies = null;",
			"	Agency targetAgencyForDeletion = null;",
			"	Map<Agency, Boolean> selectedAgencies = new HashMap<Agency, Boolean>();",
			"	List<Agency> openedAgencies = null;",
			"	int currentOpenedAgenciesIndex = 0;",
			"	Agency currentAgency = null;",
			"	static final int AGENCIES_FAST_STEP = 10;",
			"	static final int AGENCIES_NO_NAVIGATION = 0;",
			"	static final int AGENCIES_GO_FIRST = 1;",
			"	static final int AGENCIES_GO_FAST_PREVIOUS = 2;",
			"	static final int AGENCIES_GO_PREVIOUS = 3;",
			"	static final int AGENCIES_GO_NEXT = 4;",
			"	static final int AGENCIES_GO_FAST_NEXT = 5;",
			"	static final int AGENCIES_GO_LAST = 6;",
			"	static final int CLOSE_AGENCIES_POPUP = 7;",
			"	int agenciesNavigation = AGENCIES_NO_NAVIGATION;",
			"	boolean isNewAgency = false;",
			"	static final int CREATE_AGENCY = 8;",
			"	String currentAgencyName;",
			"	String currentAgencyPhone;",
			"	static final int OP_NONE = 0;",
			"	static final int OP_DELETE = 1;",
			"	int operation = OP_NONE;",
			"",
			"	public EditAgenciesAnimator() {",
			"		if (Conversation.instance().isLongRunning()) {",
			"			Conversation.instance().end(true);",
			"			Conversation.instance().leave();",
			"		}",
			"		Conversation.instance().begin();",
			"	}",
			"",
			"	@SuppressWarnings(\"unchecked\")",
			"	public List<Agency> getAgencies() {",
			"		if (agencies==null) {",
			"			agencies = entityManager.createQuery(\"from Agency\").getResultList();",
			"			selectedAgencies = new HashMap<Agency, Boolean>();",
			"		}",
			"		return agencies;",
			"	}",
			"	",
			"	public void requestAgencyDeletion(Agency agency) {",
			"		targetAgencyForDeletion = agency;",
			"		operation = OP_DELETE;",
			"	}",
			"	",
			"	public Agency getTargetAgencyForDeletion() {",
			"		return targetAgencyForDeletion;",
			"	}",
			"	",
			"	void deleteAgency(Agency agency) {",
			"		agencies.remove(agency);",
			"		entityManager.remove(agency);",
			"		selectedAgencies.remove(agency);",
			"		if (agency==currentAgency)",
			"			currentAgency = null;",
			"	}",
			"	",
			"	public Map<Agency, Boolean> getSelectedAgencies() {",
			"		return selectedAgencies;",
			"	}",
			"	",
			"	public Agency getCurrentAgency() {",
			"		return currentAgency;",
			"	}",
			"	",
			"	void setCurrentAgency(int selectedIndex) {",
			"		if (openedAgencies.size()==0)",
			"			return;",
			"		currentAgency = openedAgencies.get(index);",
			"		currentAgencyName = currentAgency.getName();",
			"		currentAgencyPhone = currentAgency.getPhone();",
			"	}",
			"	",
			"	public boolean isCurrentAgencyVisible() {",
			"		return currentAgency != null;",
			"	}",
			"	",
			"	public void setCurrentAgencyVisible(boolean visible) {",
			"	}",
			"	",
			"	void clearCurrentAgency() {",
			"		openedAgencies = null;",
			"		currentAgency = null;",
			"		isNewAgency = false;",
			"	}",
			"	",
			"	boolean isCurrentAgencyValid() {",
			"		return !FacesContext.getCurrentInstance().getMessages().hasNext();",
			"	}",
			"	",
			"	public void cancelCurrentAgency() {",
			"		GuiUtil.cancelGui();",
			"		if (isNewAgency) {",
			"			openedAgencies.remove(currentAgency);",
			"			if (currentOpenedAgenciesIndex>=openedAgencies.size())",
			"				currentOpenedAgenciesIndex = openedAgencies.size()-1;",
			"			isNewAgency = false;",
			"		}",
			"		if (openedAgencies.size()==0)",
			"			clearCurrentAgency();",
			"		else",
			"			setCurrentAgency(currentOpenedAgenciesIndex);",
			"	}",
			"	",
			"	public void validateCurrentAgency() {",
			"		if (isCurrentAgencyValid()) {",
			"			currentAgency.setName(currentAgencyName);",
			"			currentAgency.setPhone(currentAgencyPhone);",
			"			if (isNewAgency) {",
			"				entityManager.persist(currentAgency);",
			"				agencies.add(currentAgency);",
			"				isNewAgency = false;",
			"			}",
			"			return true;",
			"		}",
			"		else",
			"			return false;",
			"	}",
			"	",
			"	boolean isCurrentAgencyDirty() {",
			"		if(isNewAgency)",
			"			return true;",
			"		if (currentAgency==null)",
			"			return false;",
			"		if (!GuiUtil.equals(currentAgencyName, currentAgency.getName()))",
			"			return true;",
			"		if (!GuiUtil.equals(currentAgencyPhone, currentAgency.getPhone()))",
			"			return true;",
			"		return false;",
			"	}",
			"	",
			"	public boolean isConfirmAgenciesNavigationRequested() {",
			"		return agenciesNavigation!=AGENCIES_NO_NAVIGATION;",
			"	}",
			"	",
			"	public void cancelAgenciesNavigation() {",
			"		agenciesNavigation = AGENCIES_NO_NAVIGATION;",
			"	}",
			"	",
			"	void doAgenciesGoFirst() {",
			"		currentOpenedAgenciesIndex = 0;",
			"		setCurrentAgency(currentOpenedAgenciesIndex);",
			"	}",
			"	",
			"	public void agenciesGoFirst() {",
			"		if (isCurrentAgencyDirty())",
			"			agenciesNavigation = AGENCIES_GO_FIRST;",
			"		else",
			"			doAgenciesGoFirst();",
			"	}",
			"	",
			"	void doAgenciesGoFastPrevious() {",
			"		currentOpenedAgenciesIndex -= AGENCIES_FAST_STEP;",
			"		if (currentOpenedAgenciesIndex<0)",
			"			currentOpenedAgenciesIndex=0;",
			"		setCurrentAgency(currentOpenedAgenciesIndex);",
			"	}",
			"	",
			"	public void agenciesGoFastPrevious() {",
			"		if (isCurrentAgencyDirty())",
			"			agenciesNavigation = AGENCIES_GO_FAST_PREVIOUS;",
			"		else",
			"			doAgenciesGoFastPrevious();",
			"	}",
			"	",
			"	void doAgenciesGoPrevious() {",
			"		currentOpenedAgenciesIndex -= 1;",
			"		if (currentOpenedAgenciesIndex<0)",
			"			currentOpenedAgenciesIndex=0;",
			"		setCurrentAgency(currentOpenedAgenciesIndex);",
			"	}",
			"	",
			"	public void agenciesGoPrevious() {",
			"		if (isCurrentAgencyDirty())",
			"			agenciesNavigation = AGENCIES_GO_PREVIOUS;",
			"		else",
			"			doAgenciesGoPrevious();",
			"	}",
			"	",
			"	void doAgenciesGoNext() {",
			"		currentOpenedAgenciesIndex += 1;",
			"		if (currentOpenedAgenciesIndex>=openedAgencies.size())",
			"			currentOpenedAgenciesIndex=openedAgencies.size()-1;",
			"		setCurrentAgency(currentOpenedAgenciesIndex);",
			"	}",
			"	",
			"	public void agenciesGoNext() {",
			"		if (isCurrentAgencyDirty())",
			"			agenciesNavigation = AGENCIES_GO_NEXT;",
			"		else",
			"			doAgenciesGoNext();",
			"	}",
			"	",
			"	void doAgenciesGoFastNext() {",
			"		currentOpenedAgenciesIndex += AGENCIES_FAST_STEP;",
			"		if (currentOpenedAgenciesIndex>=openedAgencies.size())",
			"			currentOpenedAgenciesIndex=openedAgencies.size()-1;",
			"		setCurrentAgency(currentOpenedAgenciesIndex);",
			"	}",
			"	",
			"	public void agenciesGoFastNext() {",
			"		if (isCurrentAgencyDirty())",
			"			agenciesNavigation = AGENCIES_GO_FAST_NEXT;",
			"		else",
			"			doAgenciesGoFastNext();",
			"	}",
			"	",
			"	void doAgenciesGoLast() {",
			"		currentOpenedAgenciesIndex = openedAgencies.size()-1;",
			"		setCurrentAgency(currentOpenedAgenciesIndex);",
			"	}",
			"	",
			"	public void agenciesGoLast() {",
			"		if (isCurrentAgencyDirty())",
			"			agenciesNavigation = AGENCIES_GO_LAST;",
			"		else",
			"			doAgenciesGoLast();",
			"	}",
			"	",
			"	protected Agency buildAgency() {",
			"		return new Agency(\"Nom de l'agence\");",
			"	}",
			"	",
			"	public void createAgency() {",
			"		openedAgencies = new ArrayList<Agency>();",
			"		openedAgencies.add(buildAgency());",
			"		isNewAgency = true;",
			"		agenciesGoFirst();",
			"	}",
			"	",
			"	void doInsertAgency() {",
			"		currentOpenedAgenciesIndex++;",
			"		Agency agency = buildAgency();",
			"		if (currentOpenedAgenciesIndex==openedAgencies.size())",
			"			openedAgencies.add(agency);",
			"		else",
			"			openedAgencies.add(currentOpenedAgenciesIndex, agency);",
			"		isNewAgency = true;",
			"		setCurrentAgency(currentOpenedAgenciesIndex);",
			"	}",
			"	",
			"	public void insertAgency() {",
			"		if (isCurrentAgencyDirty())",
			"			agenciesNavigation = CREATE_AGENCY;",
			"		else",
			"			doInsertAgency();",
			"	}",
			"	",
			"	public boolean isCreateAgencyRendered() {",
			"		return !isNewAgency;",
			"	}",
			"	",
			"	public void closeCurrentAgency() {",
			"		if (isCurrentAgencyDirty())",
			"			agenciesNavigation = CLOSE_AGENCIES_POPUP;",
			"		else",
			"			clearCurrentAgency();",
			"	}",
			"	",
			"	void navigateInsideAgencies() {",
			"		if (agenciesNavigation==AGENCIES_GO_FIRST)",
			"			agenciesGoFirst();",
			"		else if (agenciesNavigation==AGENCIES_GO_FAST_PREVIOUS)",
			"			agenciesGoFastPrevious();",
			"		else if (agenciesNavigation==AGENCIES_GO_PREVIOUS)",
			"			agenciesGoPrevious();",
			"		else if (agenciesNavigation==AGENCIES_GO_NEXT)",
			"			agenciesGoNext();",
			"		else if (agenciesNavigation==AGENCIES_GO_FAST_NEXT)",
			"			agenciesGoFastNext();",
			"		else if (agenciesNavigation==AGENCIES_GO_LAST)",
			"			agenciesGoLast();",
			"		else if (agenciesNavigation==CLOSE_AGENCIES_POPUP)",
			"			closeCurrentAgency();",
			"		else if (agenciesNavigation==CREATE_AGENCY)",
			"			doInsertAgency();",
			"		agenciesNavigation = AGENCIES_NO_NAVIGATION;",
			"	}",
			"	",
			"	public void saveAndNavigateInsideAgencies() {",
			"		validateCurrentAgency();",
			"		navigateInsideAgencies();",
			"	}",
			"	",
			"	public void cancelAndNavigateInsideAgencies() {",
			"		cancelCurrentAgency();",
			"		navigateInsideAgencies();",
			"	}",
			"	",
			"	public String getCurrentAgencyName() {",
			"		return currentAgencyName;",
			"	}",
			"	",
			"	public void setCurrentAgencyName(String currentAgencyName) {",
			"		this.currentAgencyName = currentAgencyName;",
			"	}",
			"	",
			"	public String getCurrentAgencyPhone() {",
			"		return currentAgencyPhone;",
			"	}",
			"	",
			"	public void setCurrentAgencyPhone(String currentAgencyPhone) {",
			"		this.currentAgencyPhone = currentAgencyPhone;",
			"	}",
			"	",
			"	public boolean openSelectedAgencies() {",
			"		openedAgencies = new ArrayList<Agency>();",
			"		for (Agency agency : getAgencies()) {",
			"			if (selectedAgencies.containsKey(agency) && selectedAgencies.get(agency)) {",
			"				openedAgencies.add(agency);",
			"			}",
			"		}",
			"		agenciesGoFirst();",
			"	}",
			"	",
			"	public boolean openAllAgencies() {",
			"		openedAgencies = new ArrayList<Agency>(getAgencies());",
			"		agenciesGoFirst();",
			"	}",
			"	",
			"	public int getOperation() {",
			"		return operation;",
			"	}",
			"	",
			"	public void setOperation(int operation) {",
			"		this.operation = operation;",
			"	}",
			"	",
			"	public void cancelOperation() {",
			"		operation = OP_NONE;",
			"	}",
			"	",
			"	public void continueOperation() {",
			"		if (operation == OP_DELETE) {",
			"			if (targetAgencyForDeletion != null) {",
			"				deleteAgency(targetAgencyForDeletion);",
			"				targetAgencyForDeletion = null;",
			"			}",
			"		}",
			"		operation = OP_NONE;",
			"	}",
			"	",
			"	public boolean isConfirmRequested() {",
			"		return operation != OP_NONE;",
			"	}",
			"	",
			"	public void setConfirmRequested(boolean confirmRequested) {",
			"		if (!confirmRequested) {",
			"			cancelOperation();",
			"		}",
			"	}",
			"",
			"}"
		);
		TestUtil.assertText(page.getFaceletText(),
			"<!DOCTYPE composition PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"",
			"			\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">",
			"<ui:composition xmlns=\"http://www.w3.org/1999/xhtml\"",
			"	xmlns:s=\"http://jboss.com/products/seam/taglib\"",
			"	xmlns:ui=\"http://java.sun.com/jsf/facelets\"",
			"	xmlns:f=\"http://java.sun.com/jsf/core\"",
			"	xmlns:h=\"http://java.sun.com/jsf/html\"",
			"	xmlns:ice=\"http://www.icesoft.com/icefaces/component\"",
			"	template=\"/layout/template.xhtml\">",
			"",
			"<ui:define name=\"body\">",
			"",
			"	<h:messages styleClass=\"message\"/>",
			"",
			"	<ice:form id=\"pageForm\">",
			"		<ice:panelGroup	styleClass=\"formBorderHighlight\">",
			"",
			"			<div class=\"dialog\">",
			"				<h:panelGroup>",
			"					<ice:dataTable id=\"agencies\" value=\"#{editAgencies.agencies}\" var=\"agency\"",
			"						rows=\"10\" resizable=\"true\" columnWidths=\"200px,100px,100px\">",
			"						<ice:column>",
			"							<f:facet name=\"header\">Name</f:facet>",
			"							<ice:rowSelector value=\"#{editAgencies.selectedAgencies[agency]}\" multiple=\"true\" />",
			"							<h:outputText value=\"#{agency.name}\" />",
			"						</ice:column>",
			"						<ice:column>",
			"							<f:facet name=\"header\">Phone</f:facet>",
			"							<h:outputText value=\"#{agency.phone}\" />",
			"						</ice:column>",
			"						<ice:column>",
			"							<h:commandButton value=\"del\" action=\"#{editAgencies.requestAgencyDeletion(agency)}\" disabled=\"#{editAgencies.currentAgencyVisible}\"/>",
			"						</ice:column>",
			"					</ice:dataTable>",
			"					<ice:dataPaginator for=\"agencies\" fastStep=\"10\" paginator=\"true\" paginatorMaxPages=\"9\">",
			"						<f:facet name=\"first\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-first.gif\" style=\"border:none;\"/>",
			"						</f:facet>",
			"						<f:facet name=\"last\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-last.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"						<f:facet name=\"previous\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-previous.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"						<f:facet name=\"next\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-next.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"						<f:facet name=\"fastforward\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-ff.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"						<f:facet name=\"fastrewind\">",
			"							<ice:graphicImage url=\"/xmlhttp/css/xp/css-images/arrow-fr.gif\" style=\"border:none;\" />",
			"						</f:facet>",
			"					</ice:dataPaginator>",
			"					<h:panelGroup rendered=\"#{!editAgencies.currentAgencyVisible}\">",
			"						<h:commandButton value=\"ouvrir\" action=\"#{editAgencies.openSelectedAgencies}\" rendered=\"#{!editAgencies.currentAgencyVisible}\"/>",
			"						<h:commandButton value=\"ouvrir tout\" action=\"#{editAgencies.openAllAgencies}\" rendered=\"#{!editAgencies.currentAgencyVisible}\"/>",
			"						<h:commandButton value=\"Creer\" action=\"#{editAgencies.createAgency}\" rendered=\"#{!editAgencies.currentAgencyVisible}\"/>",
			"					</h:panelGroup>",
			"				</h:panelGroup>",
			"				<h:panelGroup rendered=\"#{editAgencies.currentAgencyVisible}\">",
			"					<div class=\"mask\"/>",
			"					<h:panelGroup style=\"position:relative\">",
			"						<s:validateAll>",
			"							<h:panelGrid columns=\"4\" rowClasses=\"prop\" columnClasses=\"name,value,name,value\">",
			"								<h:outputText value=\"Nom de l'agence : \" />",
			"								<s:decorate template=\"/layout/edit.xhtml\">",
			"									<h:inputText value=\"#{editAgencies.currentAgencyName}\" size=\"30\"/>",
			"								</s:decorate>",
			"								<h:outputText value=\"Telephone : \" />",
			"								<s:decorate template=\"/layout/edit.xhtml\">",
			"									<h:inputText value=\"#{editAgencies.currentAgencyPhone}\" size=\"10\"/>",
			"								</s:decorate>",
			"							</h:panelGrid>",
			"						</s:validateAll>",
			"						<div class=\"actionButtons\">",
			"							<h:commandButton image=\"/xmlhttp/css/xp/css-images/arrow-first.gif\" action=\"#{editAgencies.agenciesGoFirst}\"/>",
			"							<h:commandButton image=\"/xmlhttp/css/xp/css-images/arrow-fr.gif\" action=\"#{editAgencies.agenciesGoFastPrevious}\"/>",
			"							<h:commandButton image=\"/xmlhttp/css/xp/css-images/arrow-previous.gif\" action=\"#{editAgencies.agenciesGoPrevious}\"/>",
			"							<h:commandButton value=\"valider\" action=\"#{editAgencies.validateCurrentAgency}\" />",
			"							<h:commandButton value=\"creer\" action=\"#{editAgencies.insertAgency}\" rendered=\"#{editAgencies.createAgencyRendered}\"/>",
			"							<h:commandButton value=\"fermer\" action=\"#{editAgencies.closeCurrentAgency}\"/>",
			"							<h:commandButton value=\"annuler\" immediate=\"true\" action=\"#{editAgencies.cancelAndNavigateInsideAgencies}\"/>",
			"							<h:commandButton image=\"/xmlhttp/css/xp/css-images/arrow-next.gif\" action=\"#{editAgencies.agenciesGoNext}\"/>",
			"							<h:commandButton image=\"/xmlhttp/css/xp/css-images/arrow-ff.gif\" action=\"#{editAgencies.agenciesGoFastNext}\"/>",
			"							<h:commandButton image=\"/xmlhttp/css/xp/css-images/arrow-last.gif\" action=\"#{editAgencies.agenciesGoLast}\"/>",
			"						</div>",
			"					</h:panelGroup>",
			"				</h:panelGroup>",
			"			</div>",
			"		</ice:panelGroup>",
			"		<ice:panelPopup modal=\"true\" draggable=\"true\" styleClass=\"popup\" rendered=\"#{editAgencies.confirmRequested}\">",
			"			<f:facet name=\"header\">",
			"				<ice:panelGrid styleClass=\"title\" cellpadding=\"0\" cellspacing=\"0\" columns=\"2\">",
			"					<ice:outputText value=\"Confirmation\"/>",
			"				</ice:panelGrid>",
			"			</f:facet>",
			"			<f:facet name=\"body\">",
			"				<ice:panelGrid width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" column=\"1\" styleClass=\"body\">",
			"					<ice:outputText value=\"Voulez-vous supprimer l'agence : #{editAgencies.targetAgencyForDeletion.name} ?\" rendered=\"#{editAgencies.operation==1}\"/>",
			"					<div class=\"actionButtons\">",
			"						<h:commandButton value=\"valider\" action=\"#{editAgencies.continueOperation}\"/>",
			"						<h:commandButton value=\"annuler\" immediate=\"true\" action=\"#{editAgencies.cancelOperation}\"/>",
			"					</div>",
			"				</ice:panelGrid>",
			"			</f:facet>",
			"		</ice:panelPopup>",
			"		<ice:panelPopup modal=\"true\" draggable=\"true\" styleClass=\"popup\" rendered=\"#{editAgencies.confirmAgenciesNavigationRequested}\">",
			"			<f:facet name=\"header\">",
			"				<ice:panelGrid styleClass=\"title\" cellpadding=\"0\" cellspacing=\"0\" columns=\"2\">",
			"					<ice:outputText value=\"Confirmation\"/>",
			"				</ice:panelGrid>",
			"			</f:facet> ",
			"			<f:facet name=\"body\">",
			"				<ice:panelGrid width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" column=\"1\" styleClass=\"body\">",
			"					<ice:outputText value=\"Des donnees ont ete modifiees. Voulez vous continuer ?\" />",
			"					<div class=\"actionButtons\">",
			"						<h:commandButton value=\"continuer\" action=\"#{editAgencies.cancelAndNavigateInsideAgencies}\"/>",
			"						<h:commandButton value=\"sauver\" action=\"#{editAgencies.saveAndNavigateInsideAgencies}\"/>",
			"						<h:commandButton value=\"annuler\" immediate=\"true\" action=\"#{editAgencies.cancelAgenciesNavigation}\"/>",
			"					</div>",
			"				</ice:panelGrid>",
			"			</f:facet>",
			"		</ice:panelPopup>",
			"	</ice:form>",
			"</ui:define>",
			"</ui:composition>"
		);
	}
}
